package com.Junit.lock;

import java.util.concurrent.TimeUnit;

public abstract class AbstractLock {
    private Thread currentThread;
    private boolean lock;

    public Thread getCurrentThread() {
        return currentThread;
    }

    public void setCurrentThread(Thread currentThread) {
        this.currentThread = currentThread;
    }

    public boolean isLock() {
        return lock;
    }

    public void setLock(boolean lock) {
        this.lock = lock;
    }

    public boolean lock(){
        return lock(false,0,null,false);
    }
    public abstract boolean lock(boolean useTimeOut, long timeOut, TimeUnit timeUnit,boolean interrupt);


    public void unlock(){
        if(Thread.currentThread()!=getCurrentThread()){
            throw new IllegalMonitorStateException("current thread does not hold the lock");
        }
        unlock0();
        setCurrentThread(null);
    }

    public abstract void unlock0();
}
